/<template>
  <div class="head">
    <ul class="list">
      <li></li>
    </ul>
    <div class="classify">
      <div class="left">
        <h3
          v-for="(item, index) in list"
          :key="item.id"
          :class="{ on: index == activeIndex }"
          @click="activeIndex = index"
        >
          {{ item.title }}
        </h3>
        <!-- {{list }} -->
      </div>
      <div class="right" v-if="list[activeIndex]">
        <dl
          v-for="item in list[activeIndex].children"
          :key="item.id"
          @click="
            $router.push({
              name: 'Detail',
              params: {
                id: item.id,
              },
            })
          "
        >
          <dt>
            <img :src="item.img" alt="" />
          </dt>
          <dd>
            <h3>{{ item.title }}</h3>
            <p>
              <b>￥{{ item.price }}</b>
              <b>销量:{{ item.sales }}</b>
              <van-icon name="cart-o" @click="add(item.id)" @click.stop v-if="item.num" :badge="item.num"/>
               <van-icon name="cart-o" @click="add(item.id)" @click.stop v-else/>
            </p>
          </dd>
        </dl>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions, mapMutations } from "vuex";
export default {
  data() {
    return {
      activeIndex: 0,
    };
  },
  components: {},
  computed: {
    ...mapState(["list"]),
  },
  methods: {
    ...mapActions(["getlist"]),
    ...mapMutations(['addNum']),
    add(id){
      this.addNum(id)
    }
  },
  mounted() {
    this.getlist();
    // this.getClassify();
  },
};
</script>

<style lang='scss'>
.head {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .list {
    width: 100%;
    height: 80px;
    background: #ccc;
  }
  .classify {
    width: 100%;
    height: 100%;
    background: #eee;
    display: flex;
    .left {
      width: 80px;
      height: 100%;
      background: #fcc;
      margin-right: 10px;
      overflow: hidden;
      h3 {
        line-height: 30px;
      }
      .on {
        color: red;
      }
    }
    .right {
      flex: 1;
      background: #cfc;
      dl {
        width: 100%;
        height: 150px;
        border: 1px solid #ccc;
        padding: 10px;
        display: flex;
        align-items: center;
        dt {
          width: 80px;
          height: 80px;
          margin-right: 10px;
          img {
            width: 100%;
            height: 100%;
          }
        }
        dd {
          flex: 1;
          h3 {
            line-height: 50px;
          }
          p {
            display: flex;
            align-items: center;
            justify-content: space-between;
            .van-icon {
              font-size: 30px;
            }
          }
        }
      }
    }
  }
}
</style>